package com.sne.airways.basecore.aspectj;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;

/**
 * Created by IntelliJ IDEA.
 * User: 卞京帅{bjslogin#gmail.com}
 * Date: 12-11-11
 * Time: 上午10:11
 * 拦截service方法，日志记录执行时间
 */
@Aspect
public class ExecutionTimeAspect {
    private Logger logger = Logger.getLogger(getClass());

    private ExecutionTimeAspect() {
    }

    @Around(" SystemPointcuts.servicePointcut() || SystemPointcuts.daoPointcut() ")
    public Object executionTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
        MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();

        Long start = System.currentTimeMillis();
        Object result = proceedingJoinPoint.proceed();
        Long end = System.currentTimeMillis();

        logger.info("类["+proceedingJoinPoint.getTarget()+"]中方法["+methodSignature.getName()+"]的执行时间为["+(end-start)+"ms];");
        return result;
    }

}
